package interviewclassic;

import java.util.LinkedList;

/**
 * @author ZhanBo
 * @date 2020/7/31
 */
public class Solution0304 {
    public static void main(String[] args) {
        MyQueue queue = new MyQueue();

        queue.push(1);
        queue.push(2);
        System.out.println(queue.peek());
        System.out.println(queue.pop());
        System.out.println(queue.empty());

    }
}


class MyQueue {


    LinkedList<Integer> inStack;
    LinkedList<Integer> outStack;

    /** Initialize your data structure here. */
    public MyQueue() {
        inStack = new LinkedList<>();
        outStack = new LinkedList<>();
    }

    /** Push element x to the back of queue. */
    public void push(int x) {
        inStack.push(x);
    }

    /** Removes the element from in front of queue and returns that element. */
    public int pop() {
        peek();
        return outStack.pop();
    }

    /** Get the front element. */
    public int peek() {
       if (outStack.isEmpty()){
           while (!inStack.isEmpty()){
               outStack.push(inStack.pop());
           }
       }
       if (!outStack.isEmpty()) {
           return outStack.peek();
       }
       return -1;
    }

    /** Returns whether the queue is empty. */
    public boolean empty() {
        return inStack.isEmpty()&&outStack.isEmpty();
    }
}